package uk.ac.qub.midorfeed;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import uk.ac.qub.midorfeed.R;

/**
 * Class to help manage hero instantiation
 * @author Graeme
 *
 */
public class HeroManager {

	/**
	 * Method to populate a list with heroes
	 * @return - ArrayList containing heroes in the game
	 */
	public static ArrayList<Hero> populateHeroes() {

		ArrayList<Hero> heroesArray = new ArrayList<Hero>();

		heroesArray.add(new Hero("Anti-Mage", 1, R.raw.antimage,
				R.drawable.antimage));
		heroesArray.add(new Hero("Axe", 2, R.raw.axe, R.drawable.axe));
		heroesArray.add(new Hero("Bane", 3, R.raw.bane, R.drawable.bane));
		heroesArray.add(new Hero("Bloodseeker", 4, R.raw.bloodseeker,
				R.drawable.bloodseeker));
		heroesArray.add(new Hero("Crystal Maiden", 5, R.raw.crystalmaiden,
				R.drawable.crystalmaiden));
		heroesArray.add(new Hero("Drow Ranger", 6, R.raw.drowranger,
				R.drawable.drowranger));
		heroesArray.add(new Hero("Earthshaker", 7, R.raw.earthshaker,
				R.drawable.earthshaker));
		heroesArray.add(new Hero("Juggernaut", 8, R.raw.juggernaut,
				R.drawable.juggernaut));
		heroesArray.add(new Hero("Mirana", 9, R.raw.mirana, R.drawable.mirana));
		heroesArray.add(new Hero("Morphling", 10, R.raw.morphling,
				R.drawable.morphling));
		heroesArray.add(new Hero("Shadow Fiend", 11, R.raw.shadowfiend,
				R.drawable.shadowfiend));
		heroesArray.add(new Hero("Phantom Lancer", 12, R.raw.phantomlancer,
				R.drawable.phantomlancer));
		heroesArray.add(new Hero("Puck", 13, R.raw.puck, R.drawable.puck));
		heroesArray.add(new Hero("Pudge", 14, R.raw.pudge, R.drawable.pudge));
		heroesArray.add(new Hero("Razor", 15, R.raw.razor, R.drawable.razor));
		heroesArray.add(new Hero("Sand King", 16, R.raw.sandking,
				R.drawable.sandking));
		heroesArray.add(new Hero("Storm Spirit", 17, R.raw.stormspirit,
				R.drawable.stormspirit));
		heroesArray.add(new Hero("Sven", 18, R.raw.sven, R.drawable.sven));
		heroesArray.add(new Hero("Tiny", 19, R.raw.tiny, R.drawable.tiny));
		heroesArray.add(new Hero("Vengeful Spirit", 20, R.raw.vengefulspirit,
				R.drawable.vengefulspirit));
		heroesArray.add(new Hero("Windranger", 21, R.raw.windranger,
				R.drawable.windranger));
		heroesArray.add(new Hero("Zeus", 22, R.raw.zeus, R.drawable.zeus));
		heroesArray
				.add(new Hero("Kunkka", 23, R.raw.kunkka, R.drawable.kunkka));
		heroesArray.add(new Hero("Lina", 24, R.raw.lina, R.drawable.lina));
		heroesArray.add(new Hero("Lich", 25, R.raw.lich, R.drawable.lich));
		heroesArray.add(new Hero("Lion", 26, R.raw.lion, R.drawable.lion));
		heroesArray.add(new Hero("Shadow Shaman", 27, R.raw.shadowshaman,
				R.drawable.shadowshaman));
		heroesArray.add(new Hero("Slardar", 28, R.raw.slardar,
				R.drawable.slardar));
		heroesArray.add(new Hero("Tidehunter", 29, R.raw.tidehunter,
				R.drawable.tidehunter));
		heroesArray.add(new Hero("Witch Doctor", 30, R.raw.witchdoctor,
				R.drawable.witchdoctor));
		// unused hero slot heroesArray.add(new Hero("Placeholder", 31, 0));
		heroesArray.add(new Hero("Riki", 32, R.raw.riki, R.drawable.riki));
		heroesArray
				.add(new Hero("Enigma", 33, R.raw.enigma, R.drawable.enigma));
		heroesArray
				.add(new Hero("Tinker", 34, R.raw.tinker, R.drawable.tinker));
		heroesArray
				.add(new Hero("Sniper", 35, R.raw.sniper, R.drawable.sniper));
		heroesArray.add(new Hero("Necrophos", 36, R.raw.necrophos,
				R.drawable.necrophos));
		heroesArray.add(new Hero("Warlock", 37, R.raw.warlock,
				R.drawable.warlock));
		heroesArray.add(new Hero("Beastmaster", 38, R.raw.beastmaster,
				R.drawable.beastmaster));
		heroesArray.add(new Hero("Queen of Pain", 39, R.raw.queenofpain,
				R.drawable.queenofpain));
		heroesArray.add(new Hero("Venomancer", 40, R.raw.venomancer,
				R.drawable.venomancer));
		heroesArray.add(new Hero("Faceless Void", 41, R.raw.facelessvoid,
				R.drawable.facelessvoid));
		heroesArray.add(new Hero("Wraith King", 42, R.raw.wraithking,
				R.drawable.wraithking));
		heroesArray.add(new Hero("Death Prophet", 43, R.raw.deathprophet,
				R.drawable.deathprophet));
		heroesArray.add(new Hero("Phantom Assassin", 44, R.raw.phantomassassin,
				R.drawable.phantomassassin));
		heroesArray.add(new Hero("Pugna", 45, R.raw.pugna, R.drawable.pugna));
		heroesArray.add(new Hero("Templar Assassin", 46, R.raw.templarassassin,
				R.drawable.templarassassin));
		heroesArray.add(new Hero("Viper", 47, R.raw.viper, R.drawable.viper));
		heroesArray.add(new Hero("Luna", 48, R.raw.luna, R.drawable.luna));
		heroesArray.add(new Hero("Dragon Knight", 49, R.raw.dragonknight,
				R.drawable.dragonknight));
		heroesArray
				.add(new Hero("Dazzle", 50, R.raw.dazzle, R.drawable.dazzle));
		heroesArray.add(new Hero("Clockwerk", 51, R.raw.clockwerk,
				R.drawable.clockwerk));
		heroesArray.add(new Hero("Leshrac", 52, R.raw.leshrac,
				R.drawable.leshrac));
		heroesArray.add(new Hero("Nature's Prophet", 53, R.raw.naturesprophet,
				R.drawable.furion));
		heroesArray.add(new Hero("Lifestealer", 54, R.raw.lifestealer,
				R.drawable.lifestealer));
		heroesArray.add(new Hero("Dark Seer", 55, R.raw.darkseer,
				R.drawable.darkseer));
		heroesArray
				.add(new Hero("Clinkz", 56, R.raw.clinkz, R.drawable.clinkz));
		heroesArray.add(new Hero("Omniknight", 57, R.raw.omniknight,
				R.drawable.omniknight));
		heroesArray.add(new Hero("Enchantress", 58, R.raw.enchantress,
				R.drawable.enchantress));
		heroesArray
				.add(new Hero("Huskar", 59, R.raw.huskar, R.drawable.huskar));
		heroesArray.add(new Hero("Night Stalker", 60, R.raw.nightstalker,
				R.drawable.nightstalker));
		heroesArray.add(new Hero("Broodmother", 61, R.raw.broodmother,
				R.drawable.broodmother));
		heroesArray.add(new Hero("Bounty Hunter", 62, R.raw.bountyhunter,
				R.drawable.bountyhunter));
		heroesArray
				.add(new Hero("Weaver", 63, R.raw.weaver, R.drawable.weaver));
		heroesArray
				.add(new Hero("Jakiro", 64, R.raw.jakiro, R.drawable.jakiro));
		heroesArray.add(new Hero("Batrider", 65, R.raw.batrider,
				R.drawable.batrider));
		heroesArray.add(new Hero("Chen", 66, R.raw.chen, R.drawable.chen));
		heroesArray.add(new Hero("Spectre", 67, R.raw.spectre,
				R.drawable.spectre));
		heroesArray.add(new Hero("Ancient Apparition", 68,
				R.raw.ancientapparition, R.drawable.ancientapparition));
		heroesArray.add(new Hero("Doom", 69, R.raw.doom, R.drawable.doom));
		heroesArray.add(new Hero("Ursa", 70, R.raw.ursa, R.drawable.ursa));
		heroesArray.add(new Hero("Spirit Breaker", 71, R.raw.spiritbreaker,
				R.drawable.spiritbreaker));
		heroesArray.add(new Hero("Gyrocopter", 72, R.raw.gyrocopter,
				R.drawable.gyrocopter));
		heroesArray.add(new Hero("Alchemist", 73, R.raw.alchemist,
				R.drawable.alchemist));
		heroesArray.add(new Hero("Invoker", 74, R.raw.invoker,
				R.drawable.invoker));
		heroesArray.add(new Hero("Silencer", 75, R.raw.silencer,
				R.drawable.silencer));
		heroesArray.add(new Hero("Outworld Devourer", 76,
				R.raw.outworlddevourer, R.drawable.outworlddevourer));
		heroesArray.add(new Hero("Lycan", 77, R.raw.lycan, R.drawable.lycan));
		heroesArray.add(new Hero("Brewmaster", 78, R.raw.brewmaster,
				R.drawable.beastmaster));
		heroesArray.add(new Hero("Shadow Demon", 79, R.raw.shadowdemon,
				R.drawable.shadowdemon));
		heroesArray.add(new Hero("Lone Druid", 80, R.raw.lonedruid,
				R.drawable.lonedruid));
		heroesArray.add(new Hero("Chaos Knight", 81, R.raw.chaosknight,
				R.drawable.chaosknight));
		heroesArray.add(new Hero("Meepo", 82, R.raw.meepo, R.drawable.meepo));
		heroesArray.add(new Hero("Treant Protector", 83, R.raw.treantprotector,
				R.drawable.treantprotector));
		heroesArray.add(new Hero("Ogre Magi", 84, R.raw.ogremagi,
				R.drawable.ogremagi));
		heroesArray.add(new Hero("Undying", 85, R.raw.undying,
				R.drawable.undying));
		heroesArray
				.add(new Hero("Rubick", 86, R.raw.rubick, R.drawable.rubick));
		heroesArray.add(new Hero("Disruptor", 87, R.raw.disruptor,
				R.drawable.disruptor));
		heroesArray.add(new Hero("Nyx Assassin", 88, R.raw.nyxassassin,
				R.drawable.nyxassassin));
		heroesArray.add(new Hero("Naga Siren", 89, R.raw.nagasiren,
				R.drawable.nagasiren));
		heroesArray.add(new Hero("Keeper of the Light", 90, R.raw.kotl,
				R.drawable.kotl));
		heroesArray.add(new Hero("Io", 91, R.raw.wisp, R.drawable.wisp));
		heroesArray
				.add(new Hero("Visage", 92, R.raw.visage, R.drawable.visage));
		heroesArray.add(new Hero("Slark", 93, R.raw.slark, R.drawable.slark));
		heroesArray
				.add(new Hero("Medusa", 94, R.raw.medusa, R.drawable.medusa));
		heroesArray.add(new Hero("Troll Warlord", 95, R.raw.trollwarlord,
				R.drawable.trollwarlord));
		heroesArray.add(new Hero("Centaur Warrunner", 96,
				R.raw.centaurwarruner, R.drawable.centaurwarrunner));
		heroesArray
				.add(new Hero("Magnus", 97, R.raw.magnus, R.drawable.magnus));
		heroesArray.add(new Hero("Timbersaw", 98, R.raw.timbersaw,
				R.drawable.timbersaw));
		heroesArray.add(new Hero("Bristleback", 99, R.raw.bristleback,
				R.drawable.bristleback));
		heroesArray.add(new Hero("Tusk", 100, R.raw.tusk, R.drawable.tusk));
		heroesArray.add(new Hero("Skywrath Mage", 101, R.raw.skywrathmage,
				R.drawable.skywrathmage));
		heroesArray.add(new Hero("Abaddon", 102, R.raw.abaddon,
				R.drawable.abaddon));
		heroesArray.add(new Hero("Elder Titan", 103, R.raw.eldertitan,
				R.drawable.eldertitan));
		heroesArray.add(new Hero("Legion Commander", 104,
				R.raw.legioncommander, R.drawable.legioncommander));
		// unused hero heroesArray.add(new Hero("Placeholder", 105 , null));
		heroesArray.add(new Hero("Ember Spirit", 106, R.raw.emberspirit,
				R.drawable.emberspirit));
		heroesArray.add(new Hero("Earth Spirit", 107, R.raw.earthspirit,
				R.drawable.earthspirit));
		// unreleased hero heroesArray.add(new Hero("Abyssal Underlord", 108,
		// 0));
		Collections.sort(heroesArray, new HeroComparator());
		heroesArray.add(0, new Hero("Please select a hero...", 0, 0, 0));//placeholder added after sort to ensure its first on the spinner list

		return heroesArray;

	}
	/**
	 * Method used in matching the correct hero objects to their IDs located in the int[] parsed from server results
	 * @param heroIDs - []int of hero ids parsed from the server results
	 * @return - Returns a list of the recommended hero objects for use in displaying recommended heroes to user
	 */
	public static List<Hero> findHeroesByID(int[] heroIDs) {

		List<Hero> tempHeroes = HeroManager.populateHeroes();
		List<Hero> suggestedHeroes = new ArrayList<Hero>();

		for (int loop = 0; loop < heroIDs.length; loop++) {
			for (Hero hero : tempHeroes) {
				if (hero.getHeroID() == heroIDs[loop]) {
					suggestedHeroes.add(hero);
					break;
				}
			}
		}
		return suggestedHeroes;
	}
}
